package com.leejxx.article.feign;

import com.leejxx.apis.article.IArticleClient;
import com.leejxx.article.service.ApArticleService;
import com.leejxx.article.service.AuthorService;
import com.leejxx.model.article.dtos.ArticleDto;
import com.leejxx.model.article.pojos.ApAuthor;
import com.leejxx.model.common.dto.ResponseResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author LeeJx
 * @ClassName ArticleController
 * @Description TODO
 * @date 2021/2/20 11:13
 * @Version 1.0
 */
@RestController
@Slf4j
@RequestMapping("/api/v1/author")
public class ArticleFeign implements IArticleClient {
    @Autowired
    private AuthorService authorService;

    @Autowired
    private ApArticleService articleService;

    @Override
    @RequestMapping("/findByUserId/{userId}")
    public ApAuthor findByUserId(@PathVariable Integer userId) {
        log.info("[data]{}", userId);
        return authorService.findAuthorById(userId);
    }

    @Override
    @RequestMapping("/save")
    public ResponseResult save(@RequestBody ApAuthor apAuthor) {
        log.info("[data]{}", apAuthor);
        return authorService.saveAuthor(apAuthor);
    }

    @Override
    @PostMapping("/api/v1/article/save")
    public ResponseResult saveArticle(@RequestBody ArticleDto articleDto) {
        return articleService.saveArticle(articleDto);
    }

    @Override
    @GetMapping("/api/v1/author/one/{id}")
    public ApAuthor selectById(@PathVariable("id") Integer id) {
        return authorService.getById(id);
    }
}
